package my1024.app;

import java.util.HashMap;

import javax.media.j3d.ImageComponent2D;
import javax.media.j3d.Texture;
import javax.media.j3d.Texture2D;
import javax.vecmath.Color3f;

import my1024.utils.NewTextureLoader;

import com.sun.j3d.utils.image.TextureLoader;

public class Const {
	public static final float BOX_BOUND = 0.3f;
	public static final int MAX_ROW = 4;
	public static final int MAX_COL = 4;

	// colors
	// Alt Shift A toggle block select mode
	public static Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
	public static Color3f red = new Color3f(1.0f, 0.0f, 0.0f);
	public static Color3f green = new Color3f(0.0f, 1.0f, 0.0f);
	public static Color3f blue = new Color3f(0.0f, 0.0f, 1.0f);
	public static Color3f skyBlue = new Color3f(0.6f, 0.7f, 0.9f);
	public static Color3f cyan = new Color3f(0.0f, 1.0f, 1.0f);
	public static Color3f magenta = new Color3f(1.0f, 0.0f, 1.0f);
	public static Color3f yellow = new Color3f(1.0f, 1.0f, 0.0f);
	public static Color3f brightWhite = new Color3f(1.0f, 1.5f, 1.5f);
	public static Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
	public static Color3f darkGrey = new Color3f(0.15f, 0.15f, 0.15f);
	public static Color3f medGrey = new Color3f(0.3f, 0.3f, 0.3f);
	public static Color3f grey = new Color3f(0.5f, 0.5f, 0.5f);
	public static Color3f lightGrey = new Color3f(0.75f, 0.75f, 0.75f);

	public static HashMap<String, Texture2D> texturePool;

	public static void loadTextureToPool() {
		System.out.println("Wait for loading Texture!");
		texturePool = new HashMap<String, Texture2D>();

		for (int i = 1; i <= 10; ++i) {
			int targetTexture = 1 << i;
			String filename = "res/" + targetTexture + ".png";
			System.out.println("Loading file: " + filename);

			TextureLoader loader = new NewTextureLoader(filename);
			ImageComponent2D image = loader.getImage();
			if (image == null) {
				System.out.println("load failed for texture: " + filename);
			}

			// can't use parameterless constuctor
			Texture2D texture = new Texture2D(Texture.BASE_LEVEL, Texture.RGBA,
					image.getWidth(), image.getHeight());
			texture.setImage(0, image);
			texture.setEnable(true);
			texture.setMagFilter(Texture.NICEST);

			texturePool.put(new Integer(targetTexture).toString(), texture);
		}

		// TODO: (OTHER SOLUTION?) avoid get texture when not loaded
		try {
			Thread.sleep(500);
		} catch (InterruptedException e) {
			e.printStackTrace();
		} finally {
			System.out.println("Load Texture Done!");
		}
	}

	public static Texture2D getTexture(String textureName) {
		return texturePool.get(textureName);
	}
}
